#include "File.h"

void FileReader::ReadLine()
{
	char letter;
	Line *newLine = new Line;
	memset(newLine,0,sizeof(Line));
	Line *currentLineNode = newLine;
	firstLine = currentLineNode;

	for(int i=0,letter = fgetc(fp);letter!=EOF;letter = fgetc(fp),i++)
	{
		if(letter == '\n'||letter=='\r\n')
		{
			newLine = new Line;
			memset(newLine,0,sizeof(Line));
			currentLineNode->nextLine = newLine;
			currentLineNode->nextLine->previousLine = currentLineNode;
			currentLineNode = newLine;
			i=-1;
			continue;
		}
		if(i<MAXTOKEN)
		{
			currentLineNode->line[i] = letter;
			currentLineNode->usage++;
		}
		else
		{
			Line *anotherPart = new Line;
			memset(anotherPart,0,sizeof(Line));
			i=-1;
			currentLineNode->nextPart = anotherPart;
			anotherPart->previousPart = currentLineNode;
			currentLineNode = anotherPart;
		}
	}

	lastLine->nextLine = newLine;
	lastLine->nextLine->previousLine = newLine;
	lastLine = newLine;
}